import org.jsecurity.SecurityUtils
class Author extends Commenter {
    long classesId = 0
    long hostId = 0    
    long schoolId = 0
    String schoolName = ''
    String about = ""
    String aboutMargin = ""
    Boolean contactMe = false
    Site site
    String password = ''
    boolean enabled = true
    SortedSet posts = new TreeSet()
    School school
    static hasMany = [posts: Post]

    static constraints = {
        site(nullable:true) 
        classesId(nullable:false)
        schoolId(nullable:false)
        hostId(nullable:false)
        schoolName(nullable:false)
        school(nullable:false)
        password(nullable:true,blank:true)
    }

    static mapping = {
        table:"author"
        about type: "text"
        schoolId column:'sc_id'
        aboutMargin type: "text"
        cache true
        posts cache: 'nonstrict-read-write'
    }

    String toString() {
        return "${name}"
    }

    static getCurrentUser() {

        def subject = SecurityUtils.getSubject()
        def currentUser

        if (subject.authenticated) {
            currentUser = JsecUser.findByUsername(SecurityUtils.getSubject()?.getPrincipal())
        }

        currentUser

    }

}